//
//  SISSGuaranteeCompanyShowViewController.m
//  SISSAPP
//
//  Created by 袁应荣 on 2018/10/24.
//  Copyright © 2018年 优房网. All rights reserved.
//

#import "SISSGuaranteeCompanyShowViewController.h"
#import "SISSGuaranteeCompanyTypeInViewController.h"
#import "SISSHouseProgressViewController.h"
#import "SISSNetworkingManager+HouseProgress.h"


@interface SISSGuaranteeCompanyShowViewController ()

@property (weak, nonatomic) UILabel *topLabel;

/// contentView
@property (weak, nonatomic) UIView *contentView;
@property (weak, nonatomic) UILabel *companyNameTitleLabel;
@property (weak, nonatomic) UILabel *companyNameLabel;
@property (weak, nonatomic) UILabel *companyAddressTitleLabel;
@property (weak, nonatomic) UILabel *companyAddressLabel;
@property (weak, nonatomic) UIButton *modifyButton;
///
@property (strong, nonatomic) SISSGuaranteeCompanyModel *guaranteeCompanyModel;

@end

@implementation SISSGuaranteeCompanyShowViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"担保公司";
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"back"] style:UIBarButtonItemStylePlain target:self action:@selector(backItemAction)];
    [self requestData];
}

/**
 返回按钮点击事件
 */
- (void)backItemAction {
    for (UIViewController *controller in self.navigationController.viewControllers) {
        if ([controller isKindOfClass:[SISSHouseProgressViewController class]]) {
            [self.navigationController popToViewController:controller animated:YES];
        }
    }
}

- (void)requestData {
    [kNetworkManager requestGuaranteeOrganInfoWithAhbpId:self.ahbpId success:^(SISSGuaranteeCompanyModel *model) {
        self.companyNameLabel.text = model.organName;
        self.companyAddressLabel.text = model.organAddress;
        self.guaranteeCompanyModel = model;
        if (self.isHistory && !model) {
            for (UIView *view in self.view.subviews) {
                view.hidden = YES;
            }
        }
    } failed:^(NSError *error) {
        NSLog(@"%@",error);
    }];
}


- (void)modifyButtonClickAction {
    SISSGuaranteeCompanyTypeInViewController *vc = [[SISSGuaranteeCompanyTypeInViewController alloc] init];
    vc.ahbpId = self.ahbpId;
    vc.guaranteeCompanyModel = self.guaranteeCompanyModel;
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark - UI
- (void)setupSubviews {
    [super setupSubviews];
    
    UILabel *topLabel = [UILabel yyr_labelWithText:@"为您服务的担保公司" fontSize:15 textColor:SECONDARY_TEXT_COLOR];
    [self.view addSubview:topLabel];
    self.topLabel = topLabel;
    
    UIView *contentView = [[UIView alloc] init];
    contentView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:contentView];
    self.contentView = contentView;
    
    UILabel *companyNameTitleLabel = [UILabel yyr_labelWithText:@"担保公司名称：" fontSize:15 textColor:SECONDARY_TEXT_COLOR];
    [self.contentView addSubview:companyNameTitleLabel];
    self.companyNameTitleLabel = companyNameTitleLabel;
    
    UILabel *companyNameLabel = [UILabel yyr_labelWithText:@"{担保公司名称}" fontSize:15 textColor:MAIN_TEXT_COLOR];
    [self.contentView addSubview:companyNameLabel];
    self.companyNameLabel = companyNameLabel;
    
    UILabel *companyAddressTitleLabel = [UILabel yyr_labelWithText:@"担保公司地址：" fontSize:15 textColor:SECONDARY_TEXT_COLOR];
    [self.contentView addSubview:companyAddressTitleLabel];
    self.companyAddressTitleLabel = companyAddressTitleLabel;
    
    UILabel *companyAddressLabel = [UILabel yyr_labelWithText:@"{地址}" fontSize:15 textColor:MAIN_TEXT_COLOR ];
    [self.contentView addSubview:companyAddressLabel];
    self.companyAddressLabel = companyAddressLabel;
    
    UIButton *modifyButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [modifyButton setTitle:@"修改" forState:UIControlStateNormal];
    [modifyButton setBackgroundColor:MAIN_COLOR];
    [modifyButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [modifyButton addTarget:self action:@selector(modifyButtonClickAction) forControlEvents:UIControlEventTouchUpInside];
    modifyButton.layer.cornerRadius = 4;
    modifyButton.layer.masksToBounds = YES;
    [self.view addSubview:modifyButton];
    self.modifyButton = modifyButton;
}

#pragma mark - 约束
- (void)initConstraint {
    [super initConstraint];
    
    WeakSelf
    [self.topLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.mas_topLayoutGuideBottom).offset(globelMargin);
        make.left.equalTo(weakSelf.view).offset(2 * globelMargin);
    }];
    
    [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.topLabel.mas_bottom).offset(globelMargin);
        make.left.right.equalTo(weakSelf.view);
    }];
    
    [self.companyNameTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.contentView).offset(2 * globelMargin);
        make.left.equalTo(weakSelf.contentView).offset(2 * globelMargin);
    }];
    
    [self.companyNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.companyNameTitleLabel);
        make.left.equalTo(weakSelf.companyNameTitleLabel.mas_right).offset(0.5 * globelMargin);
    }];
    
    [self.companyAddressTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.companyNameTitleLabel.mas_bottom).offset(2 * globelMargin);
        make.left.equalTo(weakSelf.companyNameTitleLabel);
        make.bottom.equalTo(weakSelf.contentView).offset(-3 * globelMargin);
    }];
    
    [self.companyAddressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.companyAddressTitleLabel);
        make.left.equalTo(weakSelf.companyAddressTitleLabel.mas_right).offset(0.5 * globelMargin);
    }];
    
    [self.modifyButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.view).offset(2 * globelMargin);
        make.top.equalTo(weakSelf.companyAddressTitleLabel.mas_bottom).offset(6 * globelMargin);
        make.right.equalTo(weakSelf.view).offset(-2 * globelMargin);
        make.height.mas_equalTo(5.5 * globelMargin);
    }];
    
}


@end
